import { reject } from "lodash-es";
import { resolve } from "path";

/**
 * 获取将base64图片旋转90度
 * @param string
 * @returns string
 */
export function base64ToRoate(val: string) {
  return new Promise((resolve, reject) => {
    const img = new Image();
    img.src = val;
    img.onload = () => {
      const canvas = document.createElement("canvas");
      canvas.width = img.height;
      canvas.height = img.width;
      const ctx = canvas.getContext("2d");
      ctx?.translate(canvas.width / 2, canvas.height / 2);
      ctx?.rotate(-Math.PI / 2);
      ctx?.drawImage(img, -img.width / 2, -img.height / 2);

      const newBase64Str = canvas.toDataURL("image/png", 1.0);
      resolve(newBase64Str);
    };
  });
}
